`
https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/
`

/**
 * @param {string} word
 * @param {number} k
 * @return {number}
 */
var countOfSubstrings = function (word, k) {
  return solve(word, k) - solve(word, k + 1)
};

const all = 'aeiou'
const map = { a: 0, e: 1, i: 2, o: 3, u: 4 }
// 计算每个元音字母至少出现一次，且有 >= k 个辅音字母的子字符串的总数
function solve(word, k) {
  const n = word.length
  const cnt = new Array(5).fill(0)
  // 辅音字母的个数
  let sum = 0
  // 包含多少个辅音字母
  let count = 0
  let res = 0
  let left = 0, right = 0

  while (right < n) {
    const c = word[right++]
    if (all.includes(c)) {
      // 处理元音字母
      cnt[map[c]]++
      if (cnt[map[c]] === 1) count++
    } else {
      // 处理辅音字母
      sum++
    }

    // 关注 left - 1 的合法性
    while (count === 5 && sum >= k) {
      const d = word[left++]
      if (all.includes(d)) {
        cnt[map[d]]--
        if (cnt[map[d]] === 0) count--
      } else {
        sum--
      }
    }

    // 有 left 个
    res += left
  }

  return res
}